package fr.emse.tatiana.replayable.tabulardisplay;

import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.ui.IEditorPart;


public class SaveAsExcelAction extends Action {
	
	IEditorPart editor;
	
	public SaveAsExcelAction(String label) {
		setText(label);
		// The id is used to refer to the action in a menu or toolbar
		//setId(ICommandIds.CMD_EXPORT);
		// Associate the action with a pre-defined command, to allow key bindings.
		//setActionDefinitionId(ICommandIds.CMD_FILTER);
		//setImageDescriptor(fr.emse.tatiana.Activator.getImageDescriptor("/icons/sample2.gif"));
		this.setEnabled(false);
	}

	public void setEditor(IEditorPart editor) {
		this.editor = editor;
		setEnabled(editor != null && (editor instanceof ReplayableTabularViewer));
	}

	@Override
	public void run() {
		

		if (editor != null) {
			FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE); 
			String path = dialog.open();
			if (editor instanceof ReplayableTabularViewer) {
				((ReplayableTabularViewer)editor).doExcelExport(path);
			}
			
		}
	}
}
